#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>


int main()
{
    printf("begin:进程,pid:%d,ppid:%d\n",getpid(),getppid());
    printf("before:only one line\n");
    pid_t id  = fork();//以调用进程为模板创建一个新的进程
    printf("after:only one line\n");
    
    if(id == 0)
    {
        //子进程
        while(1)
        {
            printf("子进程,pid:%d,ppid:%d\n",getpid(),getppid());
            sleep(1);
        }
    }
    else if(id > 0)
    {
        //父进程    
        while(1)
        {
            printf("父进程,pid:%d,ppid:%d\n",getpid(),getppid());
            sleep(1);
        }
    }
    else
    {
        //error
    }

    sleep(1);
    return 0;
}
